/**
 * 
 */
package com.feib.stms.service.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.dao.DataAccessException;


/**
 * @author Jimmy Liu
 *
 */
public class DeliveryPaymentChkSumXlsResultSetExtractor extends BasePaymentFileContentXlsResultSetExtractor
{

	public DeliveryPaymentChkSumXlsResultSetExtractor(Sheet sheet, int rownum,
			Map<String, CellStyle> styles) {
		super(sheet, rownum, styles);
	}
	


	/* (non-Javadoc)
	 * @see org.springframework.jdbc.core.ResultSetExtractor#extractData(java.sql.ResultSet)
	 */
	public Object extractData(ResultSet rs) throws SQLException,
			DataAccessException 
	{
		while (rs.next()) {
			
            // data rows

            Row row = sheet.createRow(rownum++);
            row.setHeightInPoints((float) 24);
            int j = 0;
            
            // 帳號
            String accountNoValue = (String)getColumnValue(rs, "ACCOUNT_NO", String.class);
            Cell accountNoCell = row.createCell(j++);
            if (null != accountNoValue)
            	accountNoCell.setCellValue(accountNoValue);
            accountNoCell.setCellStyle(styles.get("cell")); 

            // 客戶戶名
            String customerNameValue = (String)getColumnValue(rs, "CUSTOMER_NAME", String.class);
            Cell customerNameCell = row.createCell(j++);
            if (null != customerNameValue)
            	customerNameCell.setCellValue(customerNameValue);
            customerNameCell.setCellStyle(styles.get("cell")); 
            
            // 交割金額
            Double netIncomeValue = (Double)getColumnValue(rs, "NET_AMOUNT", Double.class);
            Cell netIncomeCell = row.createCell(j++);
            if (null != netIncomeValue)
            	netIncomeCell.setCellValue(netIncomeValue);
            netIncomeCell.setCellStyle(styles.get("cell_number"));
            
            // 不足金額
            Double netPayValue = (Double)getColumnValue(rs, "LESS_AMOUNT", Double.class);
            Cell netPayCell = row.createCell(j++);
            if (null != netPayValue)
            	netPayCell.setCellValue(netPayValue);
            netPayCell.setCellStyle(styles.get("cell_number"));

            // 交割日期
            Date deliveryDateValue = (Date)getColumnValue(rs, "DELIVERY_DATE", Date.class);
            Cell deliveryDateCell = row.createCell(j++);
            if (null != deliveryDateValue)
            	deliveryDateCell.setCellValue(deliveryDateValue);
            deliveryDateCell.setCellStyle(styles.get("cell_date"));
            

            // 營業員
            String tellerValue = (String)getColumnValue(rs, "TELLER", String.class);
            Cell tellerCell = row.createCell(j++);
            if (null != tellerValue)
            	tellerCell.setCellValue(tellerValue);
            tellerCell.setCellStyle(styles.get("cell"));

            // 處理狀況代號
            //String dealResultCodeValue = (String)getColumnValue(rs, "DEAL_RESULT_CODE", String.class);
            String dealResultCodeValue = (String)getColumnValue(rs, "DEAL_RESULT_CODE_NAME", String.class);
            Cell dealResultCodeCell = row.createCell(j++);
            if (null != dealResultCodeValue)
            	dealResultCodeCell.setCellValue(dealResultCodeValue);
            dealResultCodeCell.setCellStyle(styles.get("cell")); 

            /*
            // 身份證號
            String customerIdValue = (String)getColumnValue(rs, "CUSTOMER_ID", String.class);
            Cell customerIdCell = row.createCell(j++);
            if (null != customerIdValue)
            	customerIdCell.setCellValue(customerIdValue);
            customerIdCell.setCellStyle(styles.get("cell")); 
            */
		}
		
		return null;
	}

}
